use std::fmt::Debug;

use serde::Serialize;

pub trait MessageRole: Sized + Clone + Debug {
    fn from_str(role_name: &str) -> Option<Self>;
    fn to_str(&self) -> &str;
    fn assiatant() -> Self;
    fn user() -> Self;
    fn system() -> Self;
    fn observation() -> Self;
}

// pub enum Role {
//     User,
//     Assistant,
//     System,
//     Tool,
//     Unknown,
// }

#[derive(Debug, Clone)]
pub struct Message<R> {
    pub content: String,
    pub role: R,
}

impl<R> Message<R>
where
    R: MessageRole,
{
    pub fn from_parts(role: R, content: String) -> Self {
        Self { content, role }
    }
    pub fn from_str_parts(role: &str, content: String) -> Option<Self> {
        let role = if let Some(role) = R::from_str(role) {
            role
        } else {
            return None;
        };
        Some(Self::from_parts(role, content))
    }
    pub fn role(&self) -> &R {
        &self.role
    }
    pub fn role_name(&self) -> &str {
        self.role.to_str()
    }
    pub fn content(&self) -> &str {
        &self.content
    }
}
